const product = require('../../utils/product.js')
var app = getApp()

Page({
  data: {
    index: [],
    slides: [
      { img: "../../images/CQ.png", id: "1" },
      { img: "../../images/GX.jpg", id: "2" },
      { img: "../../images/ZS.jpg", id: "3" }
    ],
    navs: [],
  },

  bindShowProductdetail: function (e) {
    wx.navigateTo({
      url: `../detail/detail?id=${e.currentTarget.dataset.id}`
    })
  },

  binddisplay: function (e) {
    console.log("AAABBBB", e.currentTarget.dataset.id);
    wx.navigateTo({
      url: `../display/display?id=${e.currentTarget.dataset.id}`
    })
  },

  onLoad: function () {
    var that = this 
    var index = []
    var s = 0
    product.getSlides(function (result) {
      var data = result.data
      console.log("首页banner的接口数据", data);
      for (var i = 0; i < data.length; i++) {
        if (data[i].parent_id == 0) {
          index[s] = data[i]
          s++
        }
      }
      that.setData({ 'item': index }) 
      wx.setStorage({
        key: "indexSlides",
        data: data
      })

      product.getbanner(4, function (resolve) {
        var data = resolve.data;
        console.log("banner_1", data);
        that.setData({ 'banner_1': data })
        wx.setStorage({
          key: "banner_1",
          data: data
        })
      })
      product.getbanner(5, function (resolve) {
        var data = resolve.data;
        console.log("banner_2", data);
        that.setData({ 'banner_2': data })
        wx.setStorage({
          key: "banner_2",
          data: data
        })
      })

    })
  }
})
